﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WEBSITE
{
    public partial class danhmuc : System.Web.UI.Page
    {
        BLL.SanPhamBLL sp = new BLL.SanPhamBLL();
        BLL.LoaiHangBLL lh = new BLL.LoaiHangBLL();
        BLL.ChungLoaiBLL cl = new BLL.ChungLoaiBLL();
        DataTable dt = new DataTable();
        // ma chung loai
        public int cid = 0;

        //ma loai hang
        public int lid = 0;

        public string ten_chung_loai;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["cid"]))
            {
                cid = int.Parse(Request.QueryString["cid"]);
                //Binding data danh sach loai hang main 
                productcat_list.DataSource = lh.dsLoaiHang(cid);
                productcat_list.DataBind();

                //Binding data danh sach loai hang left sidebar
                left_sidebar_cat.DataSource = lh.dsLoaiHang(cid);
                left_sidebar_cat.DataBind();

                dt = cl.ctChungLoai(cid).Tables[0];
                DataRow row = dt.Rows[0];
                ten_chung_loai = row["TenChungLoai"].ToString();
                
            }
            if (!String.IsNullOrEmpty(Request.QueryString["lid"]))
            {
                lid = int.Parse(Request.QueryString["lid"]);
                cid = int.Parse(lh.ctLoaiHang(lid).Tables[0].Rows[0]["MaChungLoai"].ToString());
                //Binding data danh sach loai hang left sidebar
                left_sidebar_cat.DataSource = lh.dsLoaiHang(cid);
                left_sidebar_cat.DataBind();

                productcat_list.DataSource = lh.ctLoaiHang(lid);
                productcat_list.DataBind();
            }
            else
            {

            }
            
        }

        protected void product_list_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Literal lt = (Literal)e.Item.FindControl("procat_child_id");
            lid = int.Parse(lt.Text);
            // binding data danh sach san pham main
            ListView product_list = (ListView)e.Item.FindControl("product_child_cat_list");
            product_list.DataSource = sp.dsSanPham(cid, lid, "", -1, "", -1, -1);
            product_list.DataBind();
        }
    }
}